﻿@{
    UserBLL bll = new UserBLL();    
}
<div class="widget-content">
    <div class="widget-box">
        <div class="widget-title">
            <span class="icon"><i class="icon-align-justify"></i></span>
            <h5>
                修改角色权限</h5>
        </div>
        <div class="widget-content nopadding">
            <form action="@Url.Action("EditRoles", "User")" method="post">
            <table cellpadding="0" cellspacing="0" style="border: none; width: 100%; height: 600px;">
                <tr>
                    <td style="width: 400px; height: 500px; text-align: center;">
                        @foreach (var item in bll.GetRoles())
                        {
                            <a href="@Url.Action("EditRoles", "User", new { roleid = item.Key })" class='btn btn-large @Html.Raw(item.Key == ViewBag.roleid ? "btn-danger" : "")' style="margin-bottom: 10px; width: 150px">
                                @item.Value</a><br />
                        }
                        <input id="roleid" name="roleid" type="hidden" value="@ViewBag.roleid" />
                    </td>
                    <td style="text-align: center">
                        <table cellpadding="0" cellspacing="0" border="0" width="100%" style="height: 95%">
                            @foreach (PageRole item in bll.GetSonPages(0))
                            {
                                List<PageRole> pages = bll.GetSonPages(item.Id);    
                                <tr>
                                    <td style="width: 160px; border-bottom: solid 1px #CDCDCD">
                                        <label>
                                            <input type="checkbox" name="pageValue" value="@item.Id" onchange="selectPage(this)"
                                            @Html.Raw(item.Roles.Contains(string.Format(",{0},", ViewBag.roleid)) ? "checked='checked'" : "") />
                                            @item.Name
                                        </label>
                                    </td>
                                    <td style="text-align: left; padding-left: 40px; border-bottom: solid 1px #CDCDCD">
                                        @foreach (PageRole info in pages)
                                        {
                                            <label style="display: inline;">
                                                <input type="checkbox" name="pageValue" value="@info.Id"
                                                @Html.Raw(info.Roles.Contains(string.Format(",{0},", ViewBag.roleid)) ? "checked='checked'" : "") />
                                                @info.Name
                                            </label>
                                        }
                                    </td>
                                </tr>
                            }
                        </table>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="height: 80px; padding-left: 50px; border-top: solid 1px #CDCDCD">
                        <button type="submit" class="btn btn-success" style="width: 100px;">
                            保 存</button>
                    </td>
                </tr>
            </table>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    //选中一级菜单事件
    function selectPage(obj) {
        $(obj).parents("td").eq(0).next().find(":checkbox").each(function () {
            if ($(this).attr("checked") != $(obj).attr("checked")) {
                $(this).click();
                if ($(this).attr("checked")) {
                    $(this).parent().addClass("checked");
                }
                else {
                    $(this).parent().removeClass("checked");
                }
            }
        });
    }

    var result = "@ViewBag.result";
    $(function () {
        if (result) {
            if (result == "True") {
                alert("权限修改成功!");
                location.href = location.href;
            } else {
                alert("权限修改失败!");
            }
        }
    })
    
    
</script>
